package com.design.pattern.adapter.object;

/**
 * 对象适配器
 * 对象适配器的实现也很简单,他只需要实现目标接口,并持有被适配的实例即可.
 */
public class ObjectAdapter implements TwoHoleSocket {
    public ObjectAdapter(ThreeHoleSocketInstance instance){
        this.threeHoleSocketInstance=instance;
    }
    private ThreeHoleSocketInstance threeHoleSocketInstance;
    @Override
    public void useFor2() {
        threeHoleSocketInstance.useFor3();
    }

    /**
     * 承担测试
     * @param args
     */
    public static void main(String[] args) {
        new ObjectAdapter(new ThreeHoleSocketInstance()).useFor2();
    }

}
/**
 * 目标接口:Target,我们需要的,当前可使用的规范
 */
interface TwoHoleSocket{
    public void useFor2 ();
}
/**
 * 被适配的类(当前已经存在,但是却不符合我们既定标准的实现)
 */
class ThreeHoleSocketInstance {

    public void useFor3() {
        System.out.println("您使用的是三孔插座");
    }
}
